<cfcomponent output="false">
	
	<!--- --->
	
	<cffunction name="getWorksheet" access="public" output="true" returntype="query">

		<cfreturn application.g.worksheetGateway.getWorksheet(argumentCollection=arguments) />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="getWorksheetFields" access="public" output="true" returntype="query">

		<cfreturn application.g.worksheetGateway.getWorksheetFields(argumentCollection=arguments) />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="saveWorksheetFieldUser" access="public" output="true" returntype="void">
		<cfargument name="worksheetFieldID" required="true" />
		<cfargument name="worksheetFieldUserID" required="false" />
		<cfargument name="value" required="true">

		<cfset $.database.save(
			table="worksheet_field_user",
			id=arguments.worksheetFieldUserID,
			worksheet_field_id=arguments.worksheetFieldID,
			value=arguments.value,
			user_ID=request.session.user.id
		) />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="saveTheWorksheet" access="public" output="true" returntype="string">
		<cfargument name="worksheetID" required="true" />
		<cfargument name="name" required="false" default="" />
		<cfargument name="code" required="false" default="" />
		<cfargument name="sort_order" required="true" default="" />
		<cfargument name="description" required="true" default="" />

		<cfset var local = {} />

		<cfset local.id = $.database.save(
			table="worksheet",
			id=arguments.worksheetID,
			name=arguments.name,
			code=arguments.code,
			sort_order=arguments.sort_order,
			description=arguments.description,
			field_count=-1
		) />
		
		<cfreturn local.id />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="saveTheWorksheetField" access="public" output="true" returntype="string">
		<cfargument name="worksheetID" required="true" />
		<cfargument name="worksheetFieldID" required="true" />
		<cfargument name="name" required="false" default="" />
		<cfargument name="field_number" required="false" default="" />
		<cfargument name="field_type" required="true" default="" />
		<cfargument name="description" required="true" default="" />
		<cfargument name="default_value" required="true" default="" />

		<cfset var local = {} />

		<cfset local.id = $.database.save(
			table="worksheet_field",
			id=arguments.worksheetFieldID,
			worksheet_id=arguments.worksheetID,
			name=arguments.name,
			description=arguments.description,
			field_number=arguments.field_number,
			field_type=arguments.field_type,
			default_value=arguments.default_value
		) />
		
		<cfreturn local.id />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="deleteWorksheet" access="public" output="true" returntype="void">
		<cfargument name="worksheetID" required="true" />

		<cfset var local = {} />

		<cfset local.id = $.database.delete(
			table="worksheet",
			id=arguments.worksheetID
		) />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="deleteWorksheetField" access="public" output="true" returntype="void">
		<cfargument name="worksheetFieldID" required="true" />

		<cfset var local = {} />

		<cfset local.id = $.database.delete(
			table="worksheet_field",
			id=arguments.worksheetFieldID
		) />
		
	</cffunction>
	
	<!--- --->

</cfcomponent>